package com.jsgt.greekfire.dao.model

import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.jsgt.greekfire.dao.DateTypeConverter

@Entity(tableName = "market")
class MarketBean() : Parcelable {
    @NonNull
    @PrimaryKey
    var symbol: String? = null  //名称 btc_usdt

    @ColumnInfo
    var last: Double? = null  //最新成交

    @ColumnInfo
    @TypeConverters(DateTypeConverter::class)
    var volume: Any? = null  //24小时

    @ColumnInfo
    @TypeConverters(DateTypeConverter::class)
    var changePercentage: Any? = null //涨幅  -0.38%

    @ColumnInfo
    @TypeConverters(DateTypeConverter::class)
    var dayHigh: Any? = null //24h高

    @ColumnInfo
    @TypeConverters(DateTypeConverter::class)
    var dayLow: Any? = null //24h低
    var sort: Int = 0 //排序

    constructor(parcel: Parcel) : this() {
        symbol = parcel.readString()
        last = parcel.readValue(Double::class.java.classLoader) as? Double
        volume = parcel.readValue(Any::class.java.classLoader)
        changePercentage = parcel.readValue(Any::class.java.classLoader)
        dayHigh = parcel.readValue(Any::class.java.classLoader)
        dayLow = parcel.readValue(Any::class.java.classLoader)
        sort = parcel.readInt()
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(symbol)
        parcel.writeValue(last)
        parcel.writeValue(volume)
        parcel.writeValue(changePercentage)
        parcel.writeValue(dayHigh)
        parcel.writeValue(dayLow)
        parcel.writeInt(sort)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<MarketBean> {
        override fun createFromParcel(parcel: Parcel): MarketBean {
            return MarketBean(parcel)
        }

        override fun newArray(size: Int): Array<MarketBean?> {
            return arrayOfNulls(size)
        }
    }
}